<template>
	<view>
		
		<view v-if="isSearch" class="search-wrap">
		  <view class="search-bar flex-wrap flex-direction-row">
					<image src="../../../static/search.png" class="search-ico"></image>
					<input @input="search" placeholder-class="search-placeholder" placeholder="搜索商品"/>
			</view>
		</view>
		
		
		<view v-if="dishes.length == 0 && !isSearch" class="empty-cart">您未收藏任何商品</view>
		
		<!--<scroll-view>-->
		<scroll-view v-if="dishes.length > 0 " class="right" 
		:style="'top:'+topHeight+'px;height:'+clientHeight+'px;'" scroll-y="true">
		
		  <block v-for="(item,index) in dishes" :key="index" >
		    <navigator :url="'../../category/detail?id='+ item.id " 
			class="dish flex-wrap flex-direction-row" >  
		      <image class ="dishphoto" :src="[item.goodsImages.path == null ? 'https://cgt.weikedashi.net/cgt/default.png' : item.goodsImages.path]"/>
		      <view class="flex-item">
		            <text class="title">{{item.name}}</text>
		            <view class="flex-wrap flex-direction-row" > 
		              <text class="price">￥{{item.goodsPrice.price/100}}</text>
		            </view>
		      </view>
		    </navigator>
		  </block>
		</scroll-view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shopid: 1,
				    dishes: [],
				    isSearch: true,
				    topHeight: 62,
				    clientHeight: 0
			}
		},
		onLoad(options) {
			    let that = this
			    let flag = options.search
			    let top = flag == 1 ? 62 : 15
			    if (flag == 0){
			      uni.setNavigationBarTitle({ title: '我的收藏' })
			      this.requestLoveDishes()
			    }
			    this.isSearch= flag == 1 ? true : false
			    uni.getSystemInfo({
			      success: function (res) {
			          that.topHeight= top,
			          that.clientHeight= res.windowHeight - top
			      }
			    })
		},
		onShow() {
			if ( !this.isSearch) this.requestLoveDishes()
		},
		methods: {
			  // requestLoveDishes:function(){
			  //   let that = this
			  //   uni.request({
			  //     url: that.$common.serverAddr+'/OrderSys/HandleLove',
			  //     data: {
			  //       userId: that.$common.openID,
			  //       flag: 'findAll'
			  //     },
			  //     success: function(res) {
			  //       console.log(res)
			  //       var array = []
			  //       for (const item of res.data) {
			  //         array.push(item.dish)
			  //       }
			  //       that.dishes= array
			  //     }
			  //   })
			  // },
			
			  search: function(e) {
			    let that = this
			    uni.request({
			      url: that.$common.serverAddr+'/goods/info/query',
				  method: 'POST',
			      data: { name: e.detail.value, state:1 },
			      success: function(res) {
					if (res.data.status == 200) {
						that.dishes = res.data.data.list
					}
			      }
			    })
			  }
		}
	}
</script>

<style>

.right{
	width: 100%;
	position: absolute;
}
.dish{
	padding: 20px 30rpx;
	border-bottom: 1px solid #ddd;
}

.dish .dishphoto{
	height: 150rpx;
	width: 150rpx;
	border-radius: 4px;
	margin-right: 20rpx;
	box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
}

.dish .title{
	display: block;
	font-size: 28rpx;
	margin-bottom: 10%;
}

.dish .price{
	color: orangered;
	font-size: 30rpx;
	line-height: 30px;
}

</style>
